package com.hunan.api.catv.action.vod;

import com.google.gson.JsonObject;
import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.tencent_cloud.vod.NotifyBiz;
import com.hunan.api.catv.service.biz.tencent_cloud.vod.SignatureBiz;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(Api.vod)
@Validated
public class VodAction extends BaseAction {

    private static final Logger LOGGER = LoggerFactory.getLogger(VodAction.class);

    @Autowired
    SignatureBiz signatureBiz;

    @Autowired
    NotifyBiz notifyBiz;

    @GetMapping("/sign")
    public Result sign() {
        return buildResult(signatureBiz.sign());
    }

    @PostMapping("/notify")
    public Result notify(HttpServletRequest request, @RequestBody JsonObject body) {
        LOGGER.info("腾讯VOD视频上传回调结果：" + body);
        return buildOK(notifyBiz.notify(body), "");
    }
}
